import axios from "axios";
import JSONbig from 'json-bigint'
import store from '@/store'
const request=axios.create({
    // baseURL:'http://api-toutiao-web.itheima.net',
    baseURL:'http://ttapi.research.itcast.cn/',
    transformResponse:[function (data){
        try {
            return JSONbig.parse(data)
        }catch (err){
            // console.log('转换失败',err)
            return data
        }
    }]
})
request.interceptors.request.use(function (config){
    const {user}=store.state
    if (user){
        config.headers.Authorization=`Bearer ${user.token}`
    }
    return config
},function (error){
    return Promise.reject(error)
})

export default request